package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.pojo.domain.TransferRecords;
import com.ruoyi.system.service.ITransferRecordsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 留级记录Controller
 * 
 * @author lwj
 * @date 2024-01-24
 */
@RestController
@RequestMapping("/records")
public class TransferRecordsController extends BaseController
{
    @Autowired
    private ITransferRecordsService transferRecordsService;

    /**
     * 查询留级记录列表
     */
    @RequiresPermissions("system:records:list")
    @GetMapping("/list")
    public TableDataInfo list(TransferRecords transferRecords)
    {
        startPage();
        List<TransferRecords> list = transferRecordsService.selectTransferRecordsList(transferRecords);
        return getDataTable(list);
    }

    /**
     * 导出留级记录列表
     */
    @RequiresPermissions("system:records:export")
    @Log(title = "留级记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TransferRecords transferRecords)
    {
        List<TransferRecords> list = transferRecordsService.selectTransferRecordsList(transferRecords);
        ExcelUtil<TransferRecords> util = new ExcelUtil<TransferRecords>(TransferRecords.class);
        util.exportExcel(response, list, "留级记录数据");
    }

    /**
     * 获取留级记录详细信息
     */
    @RequiresPermissions("system:records:query")
    @GetMapping(value = "/{studentId}")
    public AjaxResult getInfo(@PathVariable("studentId") Long studentId)
    {
        return success(transferRecordsService.selectTransferRecordsByStudentId(studentId));
    }

    /**
     * 新增留级记录
     */
    @RequiresPermissions("system:records:add")
    @Log(title = "留级记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TransferRecords transferRecords)
    {
        return toAjax(transferRecordsService.insertTransferRecords(transferRecords));
    }

    /**
     * 修改留级记录
     */
    @RequiresPermissions("system:records:edit")
    @Log(title = "留级记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TransferRecords transferRecords)
    {
        return toAjax(transferRecordsService.updateTransferRecords(transferRecords));
    }

    /**
     * 删除留级记录
     */
    @RequiresPermissions("system:records:remove")
    @Log(title = "留级记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{studentIds}")
    public AjaxResult remove(@PathVariable Long[] studentIds)
    {
        return toAjax(transferRecordsService.deleteTransferRecordsByStudentIds(studentIds));
    }
}
